{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Calculator for Farrow structure"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from scipy.signal import firwin, freqz\n",
    "import pylab as plt\n",
    "from utils import *\n",
    "%matplotlib inline\n",
    "np.set_printoptions(precision=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "TAPS = 32\n",
    "F_ORDER = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "taps = np.zeros((F_ORDER+1)*(TAPS))\n",
    "for i in range(F_ORDER+1):\n",
    "    c = get_c(TAPS, i/F_ORDER, 0.9)\n",
    "    for q in range(len(c)):\n",
    "        index = i+q*(F_ORDER+1)\n",
    "        taps[index] = c[q]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "farrow_data = np.zeros((F_ORDER+1)*(TAPS))\n",
    "x = np.arange(0, 1+1/F_ORDER, 1/F_ORDER)\n",
    "for i in range(TAPS):\n",
    "    y = taps[i*(F_ORDER+1) : i*(F_ORDER+1)+1+F_ORDER]\n",
    "    p = np.polyfit(x, y, F_ORDER)\n",
    "    for q in range(F_ORDER+1):\n",
    "        farrow_data[q*TAPS+i] = p[F_ORDER-q]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "print_output(farrow_data, TAPS)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
